<?php include 'template/header.php'; ?>
<?php
if(empty($_SESSION['is_logged_in'])){
	include_once 'template/forms/login_form.php';
}

if(isset($_GET['action'])){
	if(isset($_SESSION['is_logged_in'])){
		switch($_GET['action']){
			case 'read':
				
				include 'admin/users/index.php';
					//echo "<a href=" . $config['base_url'] . "index.php?action=update&id=${values['id']}>Update</a>" . " ";			
					//echo "<a href=" . $config['base_url'] . "index.php?action=delete&id=${values['id']}>Delete</a>";
							
					
			break;
			case 'update':
				
				$page->update_form();
				

			break;	
			
			case 'delete':
				$del = new User();
				$user = User::find_by_id($_GET['id']);
				if($user){
					$del->delete($user->id);
					header("location: " . $config['base_url'] . "index.php?action=read");
				}
				
			break;	
			
			case "signup":
					
				include_once 'template/forms/signup_form.php';
				$page->signup();
				
			break;
				
			case 'login':

				if($page->login()){		
					$_SESSION['is_logged_in'] = TRUE;
					header("location: " . $config['base_url'] . "index.php");			
				} 
					
			break;

			case 'logout':
				unset($_SESSION['is_logged_in']);
				unset($_SESSION['username']);
				header("location: " . $config['base_url'] . "index.php");
				exit();
			break;
				
			default: 
				
			break;
		}
	} else {
		header("location: " . $config['base_url']);
	}
}
require_once('template/footer.php');
?>

